import { GetObjectCommand } from "@aws-sdk/client-s3";
import { System } from "./System";
import { Bucket } from "../../UI/config";

export function model_info(system: System) {
  return system.connector
    .model_info()
    .then((BomInfoPath: string) => {
      const s3 = system.s3Client;
      // 获取BomInfo
      const command2 = new GetObjectCommand({
        Bucket: Bucket(),
        Key: BomInfoPath,
      });
      return s3.send(command2);
    })
    .then((BomInfoResult: any) => {
      return BomInfoResult.Body?.transformToString();
    })
    .then((strPromiseForBom: string) => {
      if (strPromiseForBom) {
        const BomInfo = JSON.parse(strPromiseForBom);
        system.parent.dataComp.setBomData(BomInfo);
        return Promise.resolve(BomInfo);
      } else {
        return Promise.reject(false);
      }
    });
}
